package chatserver.gui;


import chatserver.objects.Server;
import chatserver.objects.ServerConfig;
import chatserver.roles.ChannelRole;
import chatserver.roles.GlobalRole;
import chatserver.roles.Role;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Iterator;
import java.util.List;
import javax.swing.*;

public class MainWindow extends JFrame {

    private Server server = Server.getInstance();
    private ServerConfig config = Server.getInstance().getConfig();
    // Base Frame
    private JMenuBar menuBar = new JMenuBar();
    private JMenu menuServer = new JMenu("Server");
    private JTabbedPane mainTabPane = new JTabbedPane();
    private JPanel tabConfiguration = new JPanel(false);
    private JScrollPane scrollTabConfiguration = new JScrollPane(tabConfiguration);
    private JPanel tabConfiguration2 = new JPanel(false);
    private JScrollPane scrollTabConfiguration2 = new JScrollPane(tabConfiguration2);
    private JPanel tabChannels = new JPanel(false);
    private JPanel tabUsers = new JPanel(false);
    private JTabbedPane logTabPane = new JTabbedPane();
    private JTextArea textAreaLog = new JTextArea();
    private JScrollPane scrollPaneLog = new JScrollPane(textAreaLog);
    private JTabbedPane statusTabPane = new JTabbedPane();
    private JPanel tabStatus = new JPanel(false);
    // Tab Configuration
    private JLabel jLabel1 = new JLabel();
    private JLabel jLabel2 = new JLabel();
    private JLabel jLabel3 = new JLabel();
    private JLabel jLabel4 = new JLabel();
    private JLabel jLabel5 = new JLabel();
    private JTextField jTextFieldHost = new JTextField();
    private JTextField jTextFieldPort = new JTextField();
    private JTextField jTextFieldMaxLoginPerIp = new JTextField();
    private JTextField jTextFieldMaxNickLength = new JTextField();
    private JTextField jTextFieldDefChanSlots = new JTextField();
    private JLabel jLabel6 = new JLabel();
    private JLabel jLabel7 = new JLabel();
    private JTextField jTextFieldMaxCon = new JTextField();
    private JTextField jTextFieldMaxChan = new JTextField();
    private JLabel jLabel8 = new JLabel();
    private JLabel jLabel9 = new JLabel();
    private JLabel jLabel10 = new JLabel();
    private JLabel jLabel11 = new JLabel();
    private JTextField jTextFieldDefChanTopic = new JTextField();
    private JTextField jTextFieldFloodDelay = new JTextField();
    private JTextField jTextFieldFloodRepeat = new JTextField();
    private JTextField jTextFieldFloodLength = new JTextField();
    private JButton jButtonSave = new JButton();
    private JLabel jWallColorLabel = new JLabel();
    private JButton jWallColorButton = new JButton();
    private JLabel jServerInfoLabel = new JLabel();
    private JTextField jServerInfo = new JTextField();    
    // Tab Configuration2
    private JLabel jLabelGlobalRoles = new JLabel();
    private JList jListGlobalRoles = new JList();
    private DefaultListModel jListGlobalRolesModel = new DefaultListModel();
    private JScrollPane jListGlobalRolesScrollPane = new JScrollPane(jListGlobalRoles);
    private JButton jButtonAddGlobalRole = new JButton();
    private JButton jButtonEditGlobalRole = new JButton();
    private JButton jButtonDeleteGlobalRole = new JButton();
    private JLabel jLabelChannelRoles = new JLabel();
    private JList jListChannelRoles = new JList();
    private DefaultListModel jListChannelRolesModel = new DefaultListModel();
    private JScrollPane jListChannelRolesScrollPane = new JScrollPane(jListChannelRoles);
    private JButton jButtonAddChannelRole = new JButton();
    private JButton jButtonEditChannelRole = new JButton();
    private JButton jButtonDeleteChannelRole = new JButton();
    private JLabel jLabel61 = new JLabel();
    private JLabel jLabel71 = new JLabel();
    private JLabel jLabel81 = new JLabel();
    private JList jListResNames = new JList();
    private DefaultListModel jListResNamesModel = new DefaultListModel();
    private JScrollPane jListResNamesScrollPane = new JScrollPane(jListResNames);
    private JList jListResChanNames = new JList();
    private DefaultListModel jListResChanNamesModel = new DefaultListModel();
    private JScrollPane jListResChanNamesScrollPane = new JScrollPane(jListResChanNames);
    private JList jListBans = new JList();
    private DefaultListModel jListBansModel = new DefaultListModel();
    private JScrollPane jListBansScrollPane = new JScrollPane(jListBans);
    private JButton jButtonAddResName = new JButton();
    private JButton jButtonEditResName = new JButton();
    private JButton jButtonDelResName = new JButton();
    private JButton jButtonAddResChanName = new JButton();
    private JButton jButtonEditResChanName = new JButton();
    private JButton jButtonDelResChanName = new JButton();
    private JButton jButtonAddBan = new JButton();
    private JButton jButtonEditBan = new JButton();
    private JButton jButtonDelBan = new JButton();
    private JList jListAllowedHosts = new JList();
    private DefaultListModel jListAllowedHostsModel = new DefaultListModel();
    private JScrollPane jListAllowedHostsScrollPane = new JScrollPane(jListAllowedHosts);
    private JLabel jLabelAHost = new JLabel();
    private JButton jButtonAddAHost = new JButton();
    private JButton jButtonEditAHost = new JButton();
    private JButton jButtonDelAHost = new JButton();

    public MainWindow(String title) {

        // Base Frame
        super(title);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        int frameWidth = 960;
        int frameHeight = 805;
        setSize(frameWidth, frameHeight);
        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
        int x = (d.width - getSize().width) / 2;
        int y = (d.height - getSize().height) / 2;
        setLocation(x, y);
        Container cp = getContentPane();
        cp.setLayout(null);

        setJMenuBar(menuBar);
        menuBar.add(menuServer);
        mainTabPane.setBounds(8, 16, 761, 545);
        mainTabPane.addTab("Configuration", scrollTabConfiguration);
        mainTabPane.addTab("Adv. Configuration", scrollTabConfiguration2);
        mainTabPane.addTab("Channels", tabChannels);
        mainTabPane.addTab("Users", tabUsers);
        mainTabPane.setSelectedIndex(0);
        cp.add(mainTabPane);

        logTabPane.setBounds(8, 568, 929, 177);
        logTabPane.addTab("Log", scrollPaneLog);
        logTabPane.setSelectedIndex(0);
        cp.add(logTabPane);

        statusTabPane.setBounds(776, 16, 169, 545);
        statusTabPane.addTab("Status", tabStatus);
        statusTabPane.setSelectedIndex(0);
        cp.add(statusTabPane);

        textAreaLog.setText("");


        // Tab Configuration
        tabConfiguration.setLayout(null);
        jLabel1.setBounds(16, 232, 139, 25);
        jLabel1.setText("Max. nickname length:");
        tabConfiguration.add(jLabel1);
        jLabel2.setBounds(368, 16, 139, 25);
        jLabel2.setText("Default channel slots:");
        tabConfiguration.add(jLabel2);
        jLabel3.setBounds(16, 192, 139, 25);
        jLabel3.setText("Max. logins per IP:");
        tabConfiguration.add(jLabel3);
        jLabel4.setBounds(16, 16, 125, 25);
        jLabel4.setText("Server IP / hostname:");
        tabConfiguration.add(jLabel4);
        jLabel5.setBounds(16, 64, 131, 19);
        jLabel5.setText("Server port:");
        tabConfiguration.add(jLabel5);
        jTextFieldHost.setBounds(152, 24, 161, 25);
        tabConfiguration.add(jTextFieldHost);
        jTextFieldPort.setBounds(152, 64, 161, 25);
        tabConfiguration.add(jTextFieldPort);
        jTextFieldMaxLoginPerIp.setBounds(168, 192, 113, 25);
        tabConfiguration.add(jTextFieldMaxLoginPerIp);
        jTextFieldMaxNickLength.setBounds(168, 232, 113, 25);
        tabConfiguration.add(jTextFieldMaxNickLength);
        jTextFieldDefChanSlots.setBounds(520, 16, 97, 25);
        tabConfiguration.add(jTextFieldDefChanSlots);
        jLabel6.setBounds(16, 112, 155, 25);
        jLabel6.setText("Max. server connections:");
        tabConfiguration.add(jLabel6);
        jLabel7.setBounds(16, 152, 144, 20);
        jLabel7.setText("Max. open channels:");
        tabConfiguration.add(jLabel7);
        jTextFieldMaxCon.setBounds(168, 112, 113, 25);
        tabConfiguration.add(jTextFieldMaxCon);
        jTextFieldMaxChan.setBounds(168, 152, 113, 25);
        tabConfiguration.add(jTextFieldMaxChan);
        jLabel8.setBounds(368, 112, 123, 25);
        jLabel8.setText("Flood delay (in ms):");
        tabConfiguration.add(jLabel8);
        jLabel9.setBounds(368, 152, 151, 25);
        jLabel9.setText("Flood max. repeat count:");
        tabConfiguration.add(jLabel9);
        jLabel10.setBounds(368, 192, 115, 25);
        jLabel10.setText("Flood max. length:");
        tabConfiguration.add(jLabel10);
        jLabel11.setBounds(368, 56, 139, 25);
        jLabel11.setText("Default channel topic:");
        tabConfiguration.add(jLabel11);
        jTextFieldDefChanTopic.setBounds(520, 56, 200, 25);
        tabConfiguration.add(jTextFieldDefChanTopic);
        jTextFieldFloodDelay.setBounds(520, 112, 97, 25);
        tabConfiguration.add(jTextFieldFloodDelay);
        jTextFieldFloodRepeat.setBounds(520, 152, 97, 25);
        tabConfiguration.add(jTextFieldFloodRepeat);
        jTextFieldFloodLength.setBounds(520, 192, 97, 25);
        tabConfiguration.add(jTextFieldFloodLength);
        jButtonSave.setBounds(600, 368, 129, 33);
        jButtonSave.setText("Save");
        jButtonSave.setMargin(new Insets(2, 2, 2, 2));
        jButtonSave.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent evt) {
                jButtonSave_ActionPerformed(evt);
            }
        });
        tabConfiguration.add(jButtonSave);

        jWallColorLabel.setBounds(16, 275, 139, 25);
        jWallColorLabel.setText("Wall message color:");
        tabConfiguration.add(jWallColorLabel);

        jWallColorButton.setBounds(168, 275, 113, 25);
        Color tmp = Color.white;
        try {
            tmp = new Color(Integer.parseInt(config.getWallColor(), 16));
        }
        catch(Exception e)
        {
            
        }
        jWallColorButton.setBackground(tmp);
        jWallColorButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent evt) {
                jWallColorButton_ActionPerformed(evt);
            }
        });
        tabConfiguration.add(jWallColorButton);
        
        jServerInfoLabel.setBounds(16, 310, 139, 25);
        jServerInfoLabel.setText("Server info:");
        tabConfiguration.add(jServerInfoLabel);

        jServerInfo.setBounds(168, 310, 165, 25);
        tabConfiguration.add(jServerInfo);        
        
        // Tab Configuration2
        tabConfiguration2.setLayout(null);
        tabConfiguration2.setPreferredSize(new Dimension(700, 664));
        jLabelGlobalRoles.setBounds(32, 440, 99, 19);
        jListGlobalRolesScrollPane.setBounds(32, 64, 177, 129);
        jButtonAddGlobalRole.setBounds(176, 472, 89, 25);
        jButtonEditGlobalRole.setBounds(176, 512, 89, 25);
        jButtonDeleteGlobalRole.setBounds(176, 552, 89, 25);
        jLabelChannelRoles.setBounds(296, 440, 107, 19);
        jListChannelRolesScrollPane.setBounds(296, 472, 145, 113);
        jButtonAddChannelRole.setBounds(448, 472, 89, 25);
        jButtonEditChannelRole.setBounds(448, 512, 89, 25);
        jButtonDeleteChannelRole.setBounds(448, 552, 89, 25);
        jLabel61.setBounds(32, 24, 135, 25);
        jLabel71.setBounds(384, 24, 151, 25);
        jLabel81.setBounds(32, 224, 83, 25);
        jLabelGlobalRoles.setText("Global Roles");
        tabConfiguration2.add(jLabelGlobalRoles);
        jListGlobalRoles.setModel(jListGlobalRolesModel);
        tabConfiguration2.add(jListGlobalRolesScrollPane);
        jButtonAddGlobalRole.setText("Add");
        jButtonAddGlobalRole.setMargin(new Insets(2, 2, 2, 2));
        jButtonAddGlobalRole.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent evt) {
                jButtonAddGlobalRole_ActionPerformed(evt);
            }
        });
        tabConfiguration2.add(jButtonAddGlobalRole);
        jButtonEditGlobalRole.setText("Edit");
        jButtonEditGlobalRole.setMargin(new Insets(2, 2, 2, 2));
        jButtonEditGlobalRole.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent evt) {
                jButtonEditGlobalRole_ActionPerformed(evt);
            }
        });
        tabConfiguration2.add(jButtonEditGlobalRole);
        jButtonDeleteGlobalRole.setText("Delete");
        jButtonDeleteGlobalRole.setMargin(new Insets(2, 2, 2, 2));
        jButtonDeleteGlobalRole.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent evt) {
                jButtonDeleteGlobalRole_ActionPerformed(evt);
            }
        });
        tabConfiguration2.add(jButtonDeleteGlobalRole);
        jLabelChannelRoles.setText("Channel Roles");
        tabConfiguration2.add(jLabelChannelRoles);
        jListChannelRoles.setModel(jListChannelRolesModel);
        tabConfiguration2.add(jListChannelRolesScrollPane);
        jButtonAddChannelRole.setText("Add");
        jButtonAddChannelRole.setMargin(new Insets(2, 2, 2, 2));
        jButtonAddChannelRole.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent evt) {
                jButtonAddChannelRole_ActionPerformed(evt);
            }
        });
        tabConfiguration2.add(jButtonAddChannelRole);
        jButtonEditChannelRole.setText("Edit");
        jButtonEditChannelRole.setMargin(new Insets(2, 2, 2, 2));
        jButtonEditChannelRole.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent evt) {
                jButtonEditChannelRole_ActionPerformed(evt);
            }
        });
        tabConfiguration2.add(jButtonEditChannelRole);
        jButtonDeleteChannelRole.setText("Delete");
        jButtonDeleteChannelRole.setMargin(new Insets(2, 2, 2, 2));
        jButtonDeleteChannelRole.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent evt) {
                jButtonDeleteChannelRole_ActionPerformed(evt);
            }
        });
        tabConfiguration2.add(jButtonDeleteChannelRole);
        jLabel61.setText("Reserved nicknames:");
        tabConfiguration2.add(jLabel61);
        jLabel71.setText("Reserved channel names:");
        tabConfiguration2.add(jLabel71);
        jLabel81.setText("Banlist:");
        tabConfiguration2.add(jLabel81);
        jListResNamesScrollPane.setBounds(32, 64, 177, 129);
        jListResNames.setModel(jListResNamesModel);
        tabConfiguration2.add(jListResNamesScrollPane);
        jListResChanNames.setModel(jListResChanNamesModel);
        jListResChanNamesScrollPane.setBounds(384, 64, 177, 129);
        tabConfiguration2.add(jListResChanNamesScrollPane);
        jListBans.setModel(jListBansModel);
        jListBansScrollPane.setBounds(32, 264, 265, 129);
        tabConfiguration2.add(jListBansScrollPane);
        jButtonAddResName.setBounds(216, 64, 81, 25);
        jButtonAddResName.setText("Add");
        jButtonAddResName.setMargin(new Insets(2, 2, 2, 2));
        jButtonAddResName.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent evt) {
                jButtonAddResName_ActionPerformed(evt);
            }
        });
        tabConfiguration2.add(jButtonAddResName);
        jButtonEditResName.setBounds(216, 112, 81, 25);
        jButtonEditResName.setText("Edit");
        jButtonEditResName.setMargin(new Insets(2, 2, 2, 2));
        jButtonEditResName.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent evt) {
                jButtonEditResName_ActionPerformed(evt);
            }
        });
        tabConfiguration2.add(jButtonEditResName);
        jButtonDelResName.setBounds(216, 160, 81, 25);
        jButtonDelResName.setText("Delete");
        jButtonDelResName.setMargin(new Insets(2, 2, 2, 2));
        jButtonDelResName.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent evt) {
                jButtonDelResName_ActionPerformed(evt);
            }
        });
        tabConfiguration2.add(jButtonDelResName);
        jListGlobalRolesScrollPane.setBounds(32, 472, 137, 113);
        jButtonAddResChanName.setBounds(576, 64, 81, 25);
        jButtonEditResChanName.setBounds(576, 112, 81, 25);
        jButtonDelResChanName.setBounds(576, 160, 81, 25);
        jButtonAddResChanName.setText("Add");
        jButtonAddResChanName.setMargin(new Insets(2, 2, 2, 2));
        jButtonAddResChanName.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent evt) {
                jButtonAddResChanName_ActionPerformed(evt);
            }
        });
        tabConfiguration2.add(jButtonAddResChanName);
        jButtonEditResChanName.setText("Edit");
        jButtonEditResChanName.setMargin(new Insets(2, 2, 2, 2));
        jButtonEditResChanName.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent evt) {
                jButtonEditResChanName_ActionPerformed(evt);
            }
        });
        tabConfiguration2.add(jButtonEditResChanName);
        jButtonDelResChanName.setText("Delete");
        jButtonDelResChanName.setMargin(new Insets(2, 2, 2, 2));
        jButtonDelResChanName.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent evt) {
                jButtonDelResChanName_ActionPerformed(evt);
            }
        });
        tabConfiguration2.add(jButtonDelResChanName);
        jButtonAddBan.setBounds(320, 264, 81, 25);
        jButtonEditBan.setBounds(320, 312, 81, 25);
        jButtonDelBan.setBounds(320, 360, 81, 25);
        jButtonAddBan.setText("Add");
        jButtonAddBan.setMargin(new Insets(2, 2, 2, 2));
        jButtonAddBan.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent evt) {
                jButtonAddBan_ActionPerformed(evt);
            }
        });
        tabConfiguration2.add(jButtonAddBan);
        jButtonEditBan.setText("Edit");
        jButtonEditBan.setMargin(new Insets(2, 2, 2, 2));
        jButtonEditBan.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent evt) {
                jButtonEditBan_ActionPerformed(evt);
            }
        });
        tabConfiguration2.add(jButtonEditBan);
        jButtonDelBan.setText("Delete");
        jButtonDelBan.setMargin(new Insets(2, 2, 2, 2));
        jButtonDelBan.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent evt) {
                jButtonDelBan_ActionPerformed(evt);
            }
        });
        tabConfiguration2.add(jButtonDelBan);

        jListAllowedHosts.setModel(jListAllowedHostsModel);
        tabConfiguration2.add(jListAllowedHostsScrollPane);
        jLabelAHost.setBounds(424, 232, 127, 19);
        jLabelAHost.setText("Allowed web-servers:");
        tabConfiguration2.add(jLabelAHost);
        jListAllowedHostsScrollPane.setBounds(424, 264, 193, 129);
        jButtonAddAHost.setBounds(632, 264, 81, 25);
        jButtonEditAHost.setBounds(632, 312, 81, 25);
        jButtonDelAHost.setBounds(632, 360, 81, 25);
        jButtonAddAHost.setText("Add");
        jButtonAddAHost.setMargin(new Insets(2, 2, 2, 2));
        jButtonAddAHost.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent evt) {
                jButtonAddAHost_ActionPerformed(evt);
            }
        });
        tabConfiguration2.add(jButtonAddAHost);
        jButtonEditAHost.setText("Edit");
        jButtonEditAHost.setMargin(new Insets(2, 2, 2, 2));
        jButtonEditAHost.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent evt) {
                jButtonEditAHost_ActionPerformed(evt);
            }
        });
        tabConfiguration2.add(jButtonEditAHost);
        jButtonDelAHost.setText("Delete");
        jButtonDelAHost.setMargin(new Insets(2, 2, 2, 2));
        jButtonDelAHost.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent evt) {
                jButtonDelAHost_ActionPerformed(evt);
            }
        });
        tabConfiguration2.add(jButtonDelAHost);

        loadData();

        //
        setResizable(false);
        setVisible(true);
    }

    private void loadData() {
        loadGlobalRoleList();
        loadChannelRoleList();
    }

    protected void loadGlobalRoleList() {
        List<GlobalRole> groles = server.getConfig().getGlobalRoles();

        jListGlobalRolesModel.clear();

        Iterator<GlobalRole> iter = groles.iterator();
        while (iter.hasNext()) {
            GlobalRole gr = iter.next();

            jListGlobalRolesModel.addElement(gr);
        }
    }

    protected void loadChannelRoleList() {
        List<ChannelRole> croles = server.getConfig().getChannelRoles();

        jListChannelRolesModel.clear();

        Iterator<ChannelRole> iter = croles.iterator();
        while (iter.hasNext()) {
            ChannelRole cr = iter.next();

            jListChannelRolesModel.addElement(cr);
        }
    }

    public void jButtonSave_ActionPerformed(ActionEvent evt) {
    }

    public void jButtonAddGlobalRole_ActionPerformed(ActionEvent evt) {
        new AddRoleWindow(this, "Add Global Role", true, true);
    }

    public void jButtonEditGlobalRole_ActionPerformed(ActionEvent evt) {
        Role role = (Role) jListGlobalRoles.getSelectedValue();
        if (role == null) {
            return;
        }
        new EditRoleWindow(this, "Edit Global Role \"" + role.getName() + "\"", true, true, role);
    }

    public void jButtonDeleteGlobalRole_ActionPerformed(ActionEvent evt) {
        GlobalRole role = (GlobalRole) jListGlobalRoles.getSelectedValue();
        if (role == null) {
            return;
        }
        if (config.delGlobalRole(role)) {
            loadGlobalRoleList();
        } else {
            JOptionPane.showMessageDialog(this, "Role is still in use and thus cannot be deleted!", "error", JOptionPane.ERROR_MESSAGE);
        }
    }

    public void jButtonAddChannelRole_ActionPerformed(ActionEvent evt) {
        new AddRoleWindow(this, "Add Channel Role", true, false);
    }

    public void jButtonEditChannelRole_ActionPerformed(ActionEvent evt) {
        Role role = (Role) jListChannelRoles.getSelectedValue();
        if (role == null) {
            return;
        }
        new EditRoleWindow(this, "Edit Channel Role \"" + role.getName() + "\"", true, false, role);
    }

    public void jButtonDeleteChannelRole_ActionPerformed(ActionEvent evt) {
        ChannelRole role = (ChannelRole) jListChannelRoles.getSelectedValue();
        if (role == null) {
            return;
        }
        if (config.delChannelRole(role)) {
            loadChannelRoleList();
        } else {
            JOptionPane.showMessageDialog(this, "Role is still in use and thus cannot be deleted!", "error", JOptionPane.ERROR_MESSAGE);
        }
    }

    public void jWallColorButton_ActionPerformed(ActionEvent evt) {
        Color tmp = Color.white;
        try {
            tmp = new Color(Integer.parseInt(config.getWallColor(), 16));
        }
        catch(Exception e)
        {
            
        }
        Color newColor = JColorChooser.showDialog(this, "Choose wall message color", tmp);

        if (newColor != null) {
            jWallColorButton.setBackground(newColor);
            
            String r = Integer.toHexString(newColor.getRed());
            if(r.length() < 2)
            {
                r = "0" + r;
            }
            String g = Integer.toHexString(newColor.getGreen());
            if(g.length() < 2)
            {
                g = "0" + g;
            }            
            String b = Integer.toHexString(newColor.getBlue());      
            if(b.length() < 2)
            {
                b = "0" + b;
            }            
            String colorValue = r + g + b;
            config.setWallColor(colorValue);
        }
    }

    public void jButtonAddResName_ActionPerformed(ActionEvent evt) {
        // TODO hier Quelltext einfügen
    }

    public void jButtonEditResName_ActionPerformed(ActionEvent evt) {
        // TODO hier Quelltext einfügen
    }

    public void jButtonDelResName_ActionPerformed(ActionEvent evt) {
        // TODO hier Quelltext einfügen
    }

    public void jButtonAddResChanName_ActionPerformed(ActionEvent evt) {
        // TODO hier Quelltext einfügen
    }

    public void jButtonEditResChanName_ActionPerformed(ActionEvent evt) {
        // TODO hier Quelltext einfügen
    }

    public void jButtonDelResChanName_ActionPerformed(ActionEvent evt) {
        // TODO hier Quelltext einfügen
    }

    public void jButtonAddBan_ActionPerformed(ActionEvent evt) {
        // TODO hier Quelltext einfügen
    }

    public void jButtonEditBan_ActionPerformed(ActionEvent evt) {
        // TODO hier Quelltext einfügen
    }

    public void jButtonDelBan_ActionPerformed(ActionEvent evt) {
        // TODO hier Quelltext einfügen
    }

    public void jButtonAddAHost_ActionPerformed(ActionEvent evt) {
        // TODO hier Quelltext einfügen
    }

    public void jButtonEditAHost_ActionPerformed(ActionEvent evt) {
        // TODO hier Quelltext einfügen
    }

    public void jButtonDelAHost_ActionPerformed(ActionEvent evt) {
        // TODO hier Quelltext einfügen
    }

    public void addLog(String log) {
        textAreaLog.append(" " + log);
        textAreaLog.setCaretPosition(textAreaLog.getText().length());
    }
}
